package com.jsd2412.backend.patient.controller;

import com.jsd2412.backend.base.response.JsonResult;
import com.jsd2412.backend.patient.pojo.dto.PatientQuery;
import com.jsd2412.backend.patient.pojo.vo.PatientVO;
import com.jsd2412.backend.patient.service.PatientService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@Api(tags = "老人管理模块")
@RestController
@RequestMapping("/v1/patient/")
public class PatientController {
    @Autowired
    private PatientService patientService;

    @GetMapping("select")
    public JsonResult selectPatient(PatientQuery patientQuery) {
        log.debug("老人查询:{}", patientQuery);
        List<PatientVO> list = patientService.selectPatient(patientQuery);
        return JsonResult.ok(list);
    }

    @GetMapping("selectNoBedPatient")
    public JsonResult selectNoBedPatient() {
        log.debug("查询未分配床位的老人");
        List<PatientVO> list = patientService.selectNoBedPatient();
        for (PatientVO patientVO : list) {
            System.out.println(patientVO);
        }
        return JsonResult.ok(list);
    }

    @GetMapping("patientTotal")
    public JsonResult patientTotal() {
        log.debug("获取老人总数");
        int total = patientService.patientTotal();
        return JsonResult.ok(total);
    }
}
